const mongoose=require('mongoose');

const articleSchema =new mongoose.Schema({
    title:{
        type:String,
        maxlength:20,
        minlength:4,
        // 第二个参数是错误信息
        require:[true,'请填写文章标题']
    },
    author:{
        // ?独有数据类型
        type:mongoose.Schema.Types.ObjectId,
        // ?与User数据库关联
        ref:'User',
        requires:[true,'请传递作者']
    },
    publishDate:{
        type:Date,
        default:Date.now
    },
    cover:{
        type:String,
        default:null
    },
    content:{
        type:String
    }

})

const Article=mongoose.model('Article',articleSchema);

module.exports={
    Article
}